package com.huang.servlet;

import com.huang.datebase.UserUpdate;
import com.huang.info.UserInfo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/Update")
public class UpdateUserServlet extends HttpServlet {
	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

		HttpSession session = req.getSession();

		UserInfo userInfo = (UserInfo) session.getAttribute("userInfo");

		//判断session中是否有用户信息，没有就认为是登陆失效
		if (userInfo == null) {
			resp.sendRedirect("pages/login.jsp");
			return;
		}

		String id = req.getParameter("id");
		if (id == null || "".equals(id)) {
			req.setAttribute("errMsg", "id为空");
			req.getRequestDispatcher("pages/error.jsp").forward(req, resp);
			return;
		}

		UserUpdate userUpdate = new UserUpdate();
		userUpdate.UpdateUserInfoById(id);


	}
}
